/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.isen.WebApplicationSpringTemperature.database;

import com.isen.WebApplicationSpringTemperature.bean.Temperature;
import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;


/**
 *
 * @author isen
 */
public class TemperatureHelper {
    Session session = null;

    public TemperatureHelper() {
        this.session = TemperatureHibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    
public List getTemperatures(int startID, int endID) {
    List<Temperature> tempList = null;
    try {
        org.hibernate.Transaction tx = session.beginTransaction();
        Query q = session.createQuery ("from Temperature as temperature where temperature.id between '"+startID+"' and '"+endID+"'");
        tempList = (List<Temperature>) q.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return tempList;
}
    
public List getTemperatureByID(int tempId){
    List<Temperature> tempList = null;
    try {
        org.hibernate.Transaction tx = session.beginTransaction();
        Query q = session.createQuery ("from Temperature as temperature where temperature.id='" + tempId + "')");
        tempList = (List<Temperature>) q.list();

    } catch (Exception e) {
        e.printStackTrace();
    }

    return tempList;
}
}
